using System;
using System.ComponentModel.DataAnnotations.Schema;
using UwinEducation.Shared.Enums;

namespace UwinEducation.Domain.Entities
{
    /// <summary>
    /// 教师档期实体
    /// </summary>
    [Table("teacher_availability")]
    public class TeacherAvailability : EntityBase
    {
        /// <summary>
        /// 档期ID
        /// </summary>
        public Guid Id { get; set; }

        /// <summary>
        /// 教师ID
        /// </summary>
        public Guid TeacherId { get; set; }

        /// <summary>
        /// 开始日期
        /// </summary>
        public DateTime StartDate { get; set; }

        /// <summary>
        /// 结束日期
        /// </summary>
        public DateTime EndDate { get; set; }

        /// <summary>
        /// 星期几 (1-7, 1代表星期一)
        /// </summary>
        public int? DayOfWeek { get; set; }

        /// <summary>
        /// 开始时间 (HH:mm)
        /// </summary>
        public TimeSpan? StartTime { get; set; }

        /// <summary>
        /// 结束时间 (HH:mm)
        /// </summary>
        public TimeSpan? EndTime { get; set; }

        /// <summary>
        /// 课程类型
        /// </summary>
        public CourseType? CourseType { get; set; }

        /// <summary>
        /// 备注
        /// </summary>
        public string? Remarks { get; set; }

        /// <summary>
        /// 关联的教师
        /// </summary>
        public virtual Teacher Teacher { get; set; }

        /// <summary>
        /// 创建教师档期
        /// </summary>
        public static TeacherAvailability Create(
            Guid teacherId,
            DateTime startDate,
            DateTime endDate,
            CourseType? courseType,
            // int? dayOfWeek,
            // TimeSpan? startTime,
            // TimeSpan? endTime,
            string remarks = null)
        {
            if (startDate > endDate)
            {
                throw new ArgumentException("开始日期必须早于结束日期");
            }

            // if (dayOfWeek < 0 || dayOfWeek > 6)
            // {
            //     throw new ArgumentException("星期几必须在0-6之间");
            // }

            //if (startTime >= endTime)
            //{
            //    throw new ArgumentException("开始时间必须早于结束时间");
            //}

            return new TeacherAvailability
            {
                Id = Guid.NewGuid(),
                TeacherId = teacherId,
                StartDate = startDate,
                EndDate = endDate,
                DayOfWeek = 1,//默认值
                StartTime = TimeSpan.Zero,//默认值
                EndTime = TimeSpan.Zero,//默认值
                CourseType = courseType,
                Remarks = remarks ?? string.Empty,
                CreatedAt = DateTime.Now
            };
        }
    }
} 